package com.qili.service.supervisor.impl;

import cn.hutool.core.util.IdUtil;
import com.qili.base.mapper.BaseMapper;
import com.qili.base.service.impl.BaseServiceImpl;
import com.qili.entity.supervisor.ProjectSealRecord;
import com.qili.entity.supervisor.SupervisorFile;
import com.qili.entity.supervisor.SupervisorProject;
import com.qili.entity.supervisor.dto.ProjectSealRecordDTO;
import com.qili.mapper.supervisor.ProjectSealRecordMapper;
import com.qili.service.supervisor.ProjectSealRecordService;
import com.qili.service.supervisor.SupervisorProjectService;
import com.qili.util.CommonUtil;
import com.qili.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhaoyongke
 * @date 2021/1/11
 * @description
 */
@Service
public class ProjectSealRecordServiceImpl  extends BaseServiceImpl<ProjectSealRecord,String> implements ProjectSealRecordService {

    @Autowired
    ProjectSealRecordMapper projectSealRecordMapper;
    @Autowired
    SupervisorProjectService supervisorProjectService;
    @Override
    public BaseMapper<ProjectSealRecord, String> getMappser() {
        return projectSealRecordMapper;

    }
    /**
    * @Author:zhaoyongke
    * @Description:保存用章记录
    * @param file
    * @Date:21:50 2021/1/11
    */
    public  void saveSealRecord(SupervisorFile  file){
        String projectId=file.getProjectId();
        SupervisorProject project=supervisorProjectService.selectByPrimaryKey(projectId);
        String manager=project.getProjectManagerPerson();
        String userId=CommonUtil.getUserId();
        if(userId.equals(manager)){
            /*项目经理盖章记录*/
            ProjectSealRecord  record=new ProjectSealRecord();
            record.setSealRecordId(IdUtil.simpleUUID());
            record.setUserSealBy(CommonUtil.getUserId());
            record.setUserSealDate(DateUtil.getCurrentDateString());
            record.setFileName(file.getFileName());
            record.setFileId(file.getId());
            record.setCreateBy(userId);
            record.setCreateDate(DateUtil.getCurrentDateString());
            record.setProjectId(projectId);
            projectSealRecordMapper.insertSelective(record);
        }


    }


    /**
     * @Author:zhaoyongke
     * @Description:更新用章审核
     * @Date:21:50 2021/1/11
     */
    public  void updateSealRecord(String peojectId,String fileId){
        ProjectSealRecord  sealRecord=new ProjectSealRecord();
        sealRecord.setFileId(fileId);
        sealRecord.setProjectId(peojectId);
        List<ProjectSealRecord>  sealRecordList=projectSealRecordMapper.select(sealRecord);
        for (int i = 0; i < sealRecordList.size(); i++) {
            ProjectSealRecord sealRecordselect=  sealRecordList.get(i);
            sealRecordselect.setCheckBy(CommonUtil.getUserId());
            sealRecordselect.setCheckDate(DateUtil.getCurrentDateString());
            projectSealRecordMapper.updateByPrimaryKey(sealRecordselect);
        }


    }
    public   List<ProjectSealRecordDTO>  selectProjectSealRecordList(ProjectSealRecordDTO dto){
        List<ProjectSealRecordDTO>   recordDTOList = projectSealRecordMapper.selectProjectSealRecordList(dto);
        return  recordDTOList;
    }
}
